// pages/goodslist/goodslist.js
var app = getApp()
const $api = require('../../utils/api.js').API;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件所需的参数
    navbarData: {
      havebg: 1, //1表示显示    0表示不显示
      out: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '商品列表', //导航栏 中间的标题
      bg: '#fff', //导航背景
    },
    height: app.globalData.height,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let _this = this
    //判断是否为用户，或审核人员
    var is_admin = wx.getStorageSync('is_admin');
    if(is_admin == 1||is_admin == 2){
      wx.redirectTo({
        url: '/pages/index/index',
      })
      return
    }
    $api.getptGoods({
      login_token: wx.getStorageSync('login_token'),
      type:1
    }).then((res) => {
      var list = res.data.data;
      for (var i = 0; i < list.length; i++) {
        list[i].iconState = false;
        list[i].num = 1;
        list[i].is_buy = 0;
      }
      _this.setData({
        list: list,
        loadModal: false,
      })
    }).catch((err) => {
      _this.setData({
        loadModal: false
      })
    })
     //判断是否为iPhone X
     wx.getSystemInfo({
      success: res => {
        let modelmes = res.model;
        if (modelmes.search('iPhone X') != -1) {
          _this.setData({
            isIphoneX: true
          })
        }
      }
    })
  },

  scroll: function (e) {
    this.setData({
      scrollTop: e.detail.scrollTop
    });
    if (e.detail.scrollTop >= 30) {
      this.setData({
        headerBg: true
      })
    } else {
      this.setData({
        headerBg: false
      })
    }
  },
  //返回上一页
  out() {
    wx.navigateBack({
      delta: 1,
    })
  },
  Readingdetails(e) {
    var _this = this;
    wx.navigateTo({
      url: '/pages/Readingdetails/Readingdetails?pt=1&id=' + e.currentTarget.dataset.id,
    })
    
  },
  //进入首页
  onIndex() {
    wx.reLaunch({
      url: '/pages/index/index',
    })
  },
  //进入我的
  onMine() {
    wx.reLaunch({
      url: '/pages/mine/mine',
    })
  },
  // 进入直播
  onlive() {
    wx.reLaunch({
      url: '/pages/live/live',
    })
  },
  //进入商品列表
  ongoodslist() {
    wx.reLaunch({
      url: '/pages/goodslist/goodslist',
    })
  },
  //转发
  onShareAppMessage: function (res) {
    return {
      title: '臻元气',
      path: '/pages/goodslist/goodslist',
      imageUrl:'https://jiujinimg.tjnanguyi.com/zhenyuanqi/fx.png'
    }
  }
})